#include<iostream>
using namespace std;

struct ListNode {
      int val;
      ListNode*next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
      ListNode(int x, ListNode*next) : val(x), next(next) {}
};
 
class Solution
{
public:
    ListNode* removeNthFromEnd(ListNode* head, int n)
    {
        int size = 0;
        ListNode* cur = head;
        while (cur)
        {
            cur = cur->next;
            size++;
        }
        int de_num = size - n;
        if (de_num == 0)
        {
            head = head->next;
        }
        else
        {
            cur = head;
            de_num -= 1;
            while (de_num--)
            {
                cur = cur->next;
            }
            ListNode* next = cur->next->next;
            delete cur->next;
            cur->next = next;
        }
        return head;

    }
};

int main()
{
    return 0;
}